/*
ID:luongho3
LANG:C++
TASK:stamps
*/
#include <iostream>
#include <fstream>
using namespace std;
ifstream fin("stamps.in");
ofstream fout("stamps.out");
#define NSTAMP 51
#define MAX 2000000
int nUse, nStamp, sVal[NSTAMP], m[MAX];

int main() {
    fin >> nUse >> nStamp;
    int i,j,k;
    for (i=1;i<=nStamp;++i) {
        fin >> sVal[i];
    }
    i=1;
    m[0]=0;
    while (true) {
          m[i] = nUse+1;
          for (j=nStamp;j>=1;--j) {
              if (sVal[j] <= i) {
                 k = i-sVal[j];
                 if (m[k]+1 <= nUse) {
                    if (m[i] > m[k]+1) {
                       m[i] = m[k]+1;
                    }
                 }
              }
              else continue;
          }
          if (m[i] == nUse+1) {
             fout << i-1 << "\n";
             break;
          }
          else ++i;
    }
    return 0;
}
